var express = require('express');
var router = express.Router();
var common = require('../common');
var log = require("../log").logger("msg");

/* GET users listing. */
router.get('/', function(req, res, next) {
	res.cookie["PHPSESSION"]="MySession";	
//	var size = common.getRoomCount(global.sockets);
	log.info("GetMsg");
    res.send("GetMsg");
});
//接收推送的消息，以通知指定的用户
router.post('/',function(req,res){
  var msg=req.body.msg;
  log.info(msg);
  var size = common.getMemberCountByRoom(global.sockets,msg);
  console.log("系统共有"+common.getRoomCount(global.sockets)+"个房间 , 房间 "+msg+" 中的房间人数:"+size);
  if (size == 0) {
		 console.log("不存在");
		  res.end("0");  
  } else {
		console.log("存在");
		global.sockets.in(msg).emit('message', '推送系统消息给:'+msg);
		 res.end("1");  
  }
}); 
module.exports = router;
